<?php

include_once("../service/dishService.php");
include_once("../service/imageService.php");

$dishIds = $_POST['dishId'];
$dishId = $_GET['id'];
$page_num = $_GET['page_num'];
 
if (isset($dishIds)) {
    if (!empty($dishIds)) {
        foreach ($dishIds as $id) {
			if(!checkAssignedDish($id)){
            	removeImagesByDishId($id);
            	removeDish($id);
			} else {
				Header("Location: ../admin-page/dish.php?message=assigned&page_num=$page_num");
		        return;					
			}
        }
        Header("Location: ../admin-page/dish.php?message=deleted&page_num=$page_num");
        return;
    }
} else if (isset($dishId)) {
	if(!checkAssignedDish($dishId)){
		removeImagesByDishId($dishId);
		removeDish($dishId);
	} else {
		Header("Location: ../admin-page/dish.php?message=assigned&page_num=$page_num");
		return;
	}
    Header("Location: ../admin-page/dish.php?message=deleted&page_num=$page_num");
    return;
} else {
    Header("Location: ../admin-page/dish.php?message=nodeleted&page_num=$page_num");
}

?>